//
//  BookArchiveViewModel.swift
//  KoiAccounting
//
//  Created by 纪洪文 on 04.04.25.
//

import Foundation
class BookArchiveViewModel : KoiAccountingBaseViewModel {
    
    @Published var unArchiveState = ""
    
    @Published var archiveBooks = Array<AccountingBook>()
    
    private let bookDao = KoiAccountingDB.standard.getBookDao()
    
    func loadArchiveBooks() {
        asyncBackground {
            let result = self.bookDao.getArchiveBooks(uid: self.uid)
            self.asyncMain {
                self.archiveBooks = result
            }
        }
    }
    
    func unArchive(book: AccountingBook?) {
        guard let book = book else { return }
        asyncBackground {
            self.bookDao.unArchive(book: book)
            self.asyncMain {
                self.unArchiveState = "success"
            }
        }
    }
}
